package com.example.cadmin.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.cadmin.entity.MyRoleUser;
import com.example.cadmin.mapper.MyRoleUserMapper;
import com.example.cadmin.utils.ResponseModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author  zzsoft 
 * @since 2023-01-07
 */
@Service
public class MyRoleUserService extends ServiceImpl<MyRoleUserMapper, MyRoleUser>{

    @Resource
    public MyRoleUserMapper myRoleUserMapper;
    /*
    通过用户id返回用户角色
     */
    public ResponseModel getRoleUserByUserId(Integer userId){
        MyRoleUser myRoleUser = myRoleUserMapper.selectById(userId);
        if (myRoleUser != null){
            return ResponseModel.success(myRoleUser);
        }else{
            return  ResponseModel.fail("此用户没有关联角色");
        }
    }

    /**
     * 返回用户拥有的角色
     * @param userId
     * @return
     */
    public List<MyRoleUser> getMyRoleUserByUserId(Integer userId) {
        return myRoleUserMapper.getMyRoleUserByUserId(userId);

    }
}
